
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            list-style: none;
            text-decoration: none;
        }
        .lll{
            width: 700px;
            height: 700px;
            margin: 0 auto;
        }

        .box{
            min-width: 400px;
            max-width: 800px;
            display: flex;
        }
        .hsu{
            width: 48px;
            height: 48px;
            border-radius: 50%;
            background: url(./hshbb2.jpg) no-repeat center/cover;
            margin-right: 20px;
        }
        .box textarea{
            outline: none;
            border-color: transparent;
            resize: none;
            background: #f5f5f5;
            border-radius: 4px;
            flex: 1;
            padding: 10px;
            transition: all 0.5s;
            height: 30px;
        }
        .box textarea:focus{
            border-color: #121211;
            background: #1a0808;
            height: 50px;
        }
        .box button{
            background: #0f0707;
            color: #f1e6e6;
            border: none;
            border-radius: 4px;
            margin-left: 10px;
            width: 70px;
            cursor: pointer;}
            body{
                background:#0ef887 ;
            }
            
    </style>
</head>
<body>
    <div class="lll">
        <div class="box">
            <i class="hsu"></i>
            <textarea id="tx" placeholder="留下您的建议" rowns="2" maxlength="200"></textarea>
            <button onclick="addItem()">增加</button>
        </div>
            <ul id="goto">
            </ul>
    </div>
    
    
    <script>
        const sliderData =[]
        const ul = document.getElementById(`goto`)
        function dataList() {
            while (ul.firstChild) {

                ul.removeChild(ul.firstChild)
    }
            for (let i = 0; i < sliderData.length; i++) {
                addLiElement(sliderData[i].title, i)//添加内容
    }
        }
        function addLiElement(title, i) {
            const li = document.createElement('li') //创建li元素
            li.innerHTML = `${title}<button onclick="delItem(${i})">删除</button>` //设置li元素的文本同时设置删除按钮jia键
            ul.appendChild(li) //将li元素附加到ul里
        }

        dataList();//可以不要
        //删除添加的内容
        function delItem(i) {
            sliderData.splice(i, 1)
            dataList();
        }
        function addItem() {

            const txtTodo = document.getElementById('tx')
            const todoTitle = txtTodo.value
            sliderData.push({ id:6, title: todoTitle, isCompleted: false })
            txtTodo.value = ''//写完内容文本为空
            dataList();

        }
    </script>
</body>
</html>